package com.example.clxy.controller;

import com.example.clxy.entity.InnovationStudentGx;
import com.example.clxy.interceptor.AppToken;
import com.example.clxy.result.business.InnovationRemindResult;
import com.example.clxy.result.business.PageResult.InnovationUserFilePageResult;
import com.example.clxy.entity.dto.InnovationApplyDto;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.InnovationResult;
import com.example.clxy.result.business.PageResult.InnovationAdminPageResult;
import com.example.clxy.result.business.PageResult.InnovationStudentPageResult;
import com.example.clxy.result.business.StudentInnovationResult;
import com.example.clxy.service.InnovationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author liuhaoqi
 * @Date 2020/8/10 15:02
 * @Version 1.0
 */
@AppToken
@CrossOrigin
@RestController
@RequestMapping("InnovationController")
public class InnovationController {

    @Autowired
    InnovationService innovationService;

    /**
     * 老师新增创新实验
     *
     * @param innovationApplyDto
     * @return
     */
    @PostMapping("addInnovation")
    public WebRestResult addInnovation(@RequestBody InnovationApplyDto innovationApplyDto) {
        WebRestResult result = innovationService.addInnovation(innovationApplyDto);
        return result;
    }

    /**
     * 修改创新实验基本信息
     *
     * @param innovationApplyDto
     * @return
     */
    @PostMapping("updateInnovation")
    public WebRestResult updateInnovation(@RequestBody InnovationApplyDto innovationApplyDto) {
        WebRestResult result = innovationService.updateInnovation(innovationApplyDto);
        return result;
    }

    /**
     * 删除创新实验
     *
     * @param innovationid
     * @return
     */
    @PostMapping("deleteInnovation")
    public WebRestResult deleteInnovation(String innovationid) {
        WebRestResult result = innovationService.deleteInnovation(innovationid);
        return result;
    }

    /**
     * 老师发起创新实验申请
     *
     * @param innovationid
     * @return
     */
    @PostMapping("applyInnovation")
    public WebRestResult applyInnovation(String innovationid) {
        WebRestResult result = innovationService.applyInnovation(innovationid);
        return result;
    }

    /**
     * 老师端撤回创新实验,将数据库表中的applystatus为0
     *
     * @param innovationid
     * @return
     */
    @PostMapping("withdrawInnovation")
    public WebRestResult withdrawInnovation(String innovationid) {
        WebRestResult result = innovationService.withdrawInnovation(innovationid);
        return result;
    }

    /**
     * 管理员审批创新实验，传入状态 状态1002表示审核已通过 1003表示审核拒绝 并传入理由
     *
     * @param innovationid
     * @param applystatus
     * @param rejectreason
     * @return
     */
    @PostMapping("approveInnovation")
    public WebRestResult approveInnovation(String innovationid, String applystatus, String rejectreason) {
        WebRestResult result = innovationService.approveInnovation(innovationid, applystatus, rejectreason);
        return result;
    }

    /**
     * 学生申请报名创新实验
     *
     * @param innovationid
     * @param studentid
     * @param applyreason
     * @param file
     * @return
     */
//    @PostMapping("applyInnovationStudent")
//    public WebRestResult applyInnovationStudent(String innovationid, String studentid, String applyreason
//            , MultipartFile file) {
//        WebRestResult result = innovationService.applyInnovationStudent(innovationid, studentid, applyreason, file);
//        return result;
//    }

    /**
     * 学生撤回创新实验申请
     *
     * @param innovationid
     * @param studentid
     * @return
     */
    @PostMapping("withdrawInnovationStudent")
    public WebRestResult withdrawInnovationStudent(String innovationid, String studentid, String withdrawreason) {
        WebRestResult result = innovationService.withdrawInnovationStudent(innovationid, studentid, withdrawreason);
        return result;
    }

    /**
     * 学生上传创新实验的文件,返回一个文件链接给前端，可上传多个
     *
     * @param file
     * @param innovationid
     * @param userid
     * @return
     */
    @PostMapping("uploadProjectFile")
    public WebRestResult uploadProjectFile(MultipartFile file, String innovationid, String userid) {
        WebRestResult result = innovationService.uploadProjectFile(file, innovationid, userid);
        return result;
    }

    /**
     * 学生简历上传接口
     *
     * @param file
     * @param studentid
     * @param innovationid
     * @return
     */
    @PostMapping("uploadApplyFile")
    public WebRestResult uploadApplyFile(MultipartFile file, String studentid, String innovationid) {
        WebRestResult result = innovationService.uploadApplyFile(file, studentid, innovationid);
        return result;
    }

    /**
     * 学生申请创新实验
     *
     * @param innovationStudent
     * @return
     */
    @PostMapping("addInnovationStudent")
    public WebRestResult addInnovationStudent(@RequestBody InnovationStudentGx innovationStudent) {
        WebRestResult result = innovationService.addInnovationStudent(innovationStudent);
        return result;
    }

    /**
     * 学生更新申请创新实验信息
     *
     * @param innovationStudent
     * @return
     */
    @PostMapping("updateInnovationStudent")
    public WebRestResult updateInnovationStudent(@RequestBody InnovationStudentGx innovationStudent) {
        WebRestResult result = innovationService.updateInnovationStudent(innovationStudent);
        return result;
    }

    /**
     * 老师审核学生申请创新实验 0代表所有创新实验  1001代表待审核，1002代表已通过，1003代表已拒绝
     *
     * @param studentid
     * @param applystatus
     * @param rejectreason
     * @return
     */
    @PostMapping("approveInnovationByTeacher")
    public WebRestResult approveInnovationByTeacher(String innovationid, String studentid, String applystatus, String rejectreason) {
        WebRestResult result = innovationService.approveInnovationByTeacher(innovationid, studentid, applystatus, rejectreason);
        return result;
    }

    /**
     * 管理员根据创新实验id获取创新实验信息
     *
     * @param innovationid
     * @return
     */
    @GetMapping("getInnovationByIdAdmin")
    public InnovationResult getInnovationById(String innovationid) {
        InnovationResult result = innovationService.getInnovationByIdTeacher(innovationid, null);
        return result;
    }

    /**
     * 管理员获取创新实验信息列表
     *
     * @param innovationname
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("getInnovationListByAdmin")
    public PageResult<InnovationAdminPageResult> getInnovationListByAdmin(String innovationname, String applystatus, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = innovationService.getInnovationListByAdmin(innovationname, applystatus, page, pagesize);
        return result;
    }

    /**
     * 老师端获取创新实验列表信息
     *
     * @param innovationname
     * @param teacherid
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("getInnovationListByTeacher")
    public PageResult<InnovationAdminPageResult> getInnovationListByTeacher(String innovationname, String teacherid, String applystatus, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = innovationService.getInnovationListByTeacher(innovationname, teacherid, applystatus, page, pagesize);
        return result;
    }

    /**
     * 老师端根据创新实验id获取单个创新实验的信息
     *
     * @param innovationid
     * @return
     */
    @GetMapping("getInnovationByIdTeacher")
    public InnovationResult getInnovationByIdTeacher(String innovationid, String teacherid) {
        InnovationResult result = innovationService.getInnovationByIdTeacher(innovationid, teacherid);
        return result;
    }

    /**
     * 学生端根据创新实验id得到创新实验基本信息
     *
     * @param innovationid
     * @return
     */
    @GetMapping("getInnovationByIdStudent")
    public StudentInnovationResult getInnovationByIdStudent(String innovationid, String studentid) {
        StudentInnovationResult result = innovationService.getInnovationByIdStudent(innovationid, studentid);
        return result;
    }

    /**
     * 学生端获取他已经申请等所有状态的创新实验列表信息
     * 学生端获取创新实验列表信息
     *
     * @param innovationname
     * @param studentid
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("getInnovationListByStudent")
    public PageResult<InnovationAdminPageResult> getInnovationListByStudent(String innovationname, String studentid, String applystatus, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = innovationService.getInnovationListByStudent(innovationname, studentid, applystatus, page, pagesize);
        return result;
    }

    /**
     * 学生获取可申请的创新实验列表
     *
     * @param innovationname
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("getInnovationListToApply")
    public PageResult<InnovationAdminPageResult> getInnovationListToApply(String innovationname, String studentid, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = innovationService.getInnovationListToApply(innovationname, studentid, page, pagesize);
        return result;
    }

    /**
     * 老师操作完成此创新实验 0代表未完成 1代表已经完成
     *
     * @param teacherid
     * @param innovationid
     * @return
     */
    @PostMapping("finishInnovationByTeacher")
    public WebRestResult finishInnovationByTeacher(String teacherid, String innovationid) {

        WebRestResult result = innovationService.finishInnovationByTeacher(teacherid, innovationid);
        return result;
    }

    /**
     * 根据创新实验id和学生id得到一个学生的所有信息
     *
     * @param innovationid
     * @param studentid
     * @return
     */
    @GetMapping("getInnovationStudentInfobyId")
    public StudentInnovationResult getInnovationStudentInfobyId(String innovationid, String studentid) {
        StudentInnovationResult result = innovationService.getInnovationStudentInfobyId(innovationid, studentid);
        return result;
    }

    /**
     * 根据创新实验id 老师id 申请状态得到老师某个创新实验下申请的学生的列表
     *
     * @param teacherid
     * @param innovationid
     * @param applystatus
     * @return
     */
    @GetMapping("getStudentListByIdAndStatus")
    public PageResult<InnovationStudentPageResult> getStudentListByIdAndStatus(String teacherid, String innovationid, String applystatus, int page, int pagesize) {
        PageResult<InnovationStudentPageResult> result = innovationService.getStudentListByIdAndStatus(teacherid, innovationid, applystatus, page, pagesize);
        return result;
    }

    /**
     * Web学生端获取他已经申请的所有状态的创新实验列表信息
     *
     * @param innovationname
     * @param studentid
     * @param applystatus
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("getInnovationListByStudentWeb")
    public PageResult<InnovationAdminPageResult> getInnovationListByStudentWeb(String innovationname, String studentid, String applystatus, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = innovationService.getInnovationListByStudentWeb(innovationname, studentid, applystatus, page, pagesize);
        return result;
    }

    /**
     * 老师获取申请了他创新实验的所有学生信息
     *
     * @param innovationname
     * @param teacherid
     * @param applystatus
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("getStudentListByTeacherWeb")
    public PageResult<InnovationStudentPageResult> getStudentListByTeacherWeb(String innovationname, String teacherid, String applystatus, int page, int pagesize) {
        PageResult<InnovationStudentPageResult> result = innovationService.getStudentListByTeacherWeb(innovationname, teacherid, applystatus, page, pagesize);
        return result;
    }

    /**
     * 学生端上传项目文件 ，可以上传多个文件
     *
     * @param innovationid
     * @param studentid
     * @param projectfile
     * @return
     */
    @PostMapping("uploadProjectfileByStudent")
    public WebRestResult uploadProjectfileByStudent(String innovationid, String studentid, String projectfile) {
        WebRestResult result = innovationService.uploadProjectfileByStudent(innovationid, studentid, projectfile);
        return result;
    }

    @GetMapping("getProjectfileList")
    public PageResult<InnovationUserFilePageResult> getProjectfileList(String innovationid, int page, int pagesize) {
        PageResult<InnovationUserFilePageResult> result = innovationService.getProjectfileList(innovationid, page, pagesize);
        return result;
    }

    @PostMapping("deleteProjectfile")
    public WebRestResult deleteProjectfile(String innovationid, String userid, String projectfile) {
        WebRestResult result = innovationService.deleteProjectfile(innovationid, userid, projectfile);
        return result;
    }

    @GetMapping("getInnovationRemindByTeacher")
    public PageResult<InnovationRemindResult> getInnovationRemindByTeacher(String teacherid) {
        PageResult<InnovationRemindResult> result = innovationService.getInnovationRemindByTeacher(teacherid);
        return result;
    }
}


